package cron

import (
	"github.com/robfig/cron"
	"zimuzu_cvn_web_api/config"
	"zimuzu_cvn_web_api/pkg/e"
	"zimuzu_cvn_web_api/service"
)

func Init() error {

	c := cron.New() // 新建一个定时任务对象
	//c.AddFunc("*/1 * * * ?", func() {
	//	e.Log("info", "hello world")
	//})

	if config.C.RunMode == "release" {
		//if true {
		c.AddFunc(e.CronSpecSec10, service.InitCvnAmountSign)
		c.AddFunc(e.CronSpecSec10, service.InitUsdtAmountSign)
		c.AddFunc(e.CronSpecSec10, service.InitWalletAddressSign)

		c.AddFunc(e.CronSpecMin30, service.UpdateSlideShowDb)
		c.AddFunc(e.CronSpecMin1, service.CvntPledgeDraw)
		c.AddFunc(e.CronSpecMin1, service.ExpireAgent)

		//生成金至尊码
		c.AddFunc(e.CronSpecSec30, service.GenVipCode)
		//生成令牌
		c.AddFunc(e.CronSpecSec10, service.GenTokenTask)
		//修改支付超时的令牌订单状态
		c.AddFunc(e.CronSpecMin30, service.TokenOrderOverdueDeal)
		//令牌回购队列检查
		c.AddFunc(e.CronSpecMin2, service.DealBuybackQueue)
		//生成令牌回购订单
		c.AddFunc(e.CronSpecMin3, service.GenBuybackOrder)
		c.AddFunc(e.CronSpecMin5, RentOrderExpire)
		// 更新每天结点数   1
		//c.AddFunc(e.SpecGlobalNodeNum, UpdateGlobalNodeNums)
		// 计算租用令牌用户的收益能力   1
		//c.AddFunc(e.SpecMiningCapacity, SuperMinerMiningCapacity)
		// 网心流量接口    1
		//c.AddFunc(e.SpecWxNodeFlow, MgNodeFlows)
		// 钛雾流量获取
		c.AddFunc(e.SpecTwNodeFlow, MgTwNodeFlows)
		//// 网心结点信息 在线时长接口   1
		//c.AddFunc(e.SpecWxNodeInfo, MgNodeInfo)
		//// 每个月28号补发CVN     1
		//c.AddFunc(e.SpecSubsidyPayment, SubsidyPayment)
		//// 每天12点自动从余额补充到保证金  1
		//c.AddFunc(e.SpecSupplyTokenCvn, SupplyTokenPledgingCvn)
		//// 网心结算统计   1
		//c.AddFunc(e.SpecStatisticalForYx, StatisticalStage)
		// 多线路结算统计
		c.AddFunc(e.SpecStatisticalForYx, MultipleStatisticalStage)
		c.AddFunc(e.SpecPaymentToProfitDetail, MultiplePaymentToProfitDetail)
		//// 结算给租用令牌用户统计  1
		//c.AddFunc(e.SpecPaymentForRentUser, PaymentForRent)
		//// 结算发放
		//c.AddFunc(e.SpecPaymentForYx, PaymentForMgNode)
		//// 超级结点结算  1
		//c.AddFunc(e.SpecPaymentSuper, PaymentSuper)
		//// 首年分红   1
		//c.AddFunc(e.SpecSuperFirstYear, PaymentSuperFirstYear)
		//CVNT收款
		c.AddFunc(e.CronSpecMin1, CvntRecharge)
		//CVNT转账
		c.AddFunc(e.CronSpecMin1, CvntTransfer)
		//USDT收款
		c.AddFunc(e.CronSpecMin1, UsdtRecharge)
		//USDT转账
		c.AddFunc(e.CronSpecMin1, UsdtTransfer)

		//日看板
		c.AddFunc(e.SpecAddDailyBoard, AddDailyBoard)
		//处理离线数据
		c.AddFunc(e.SpecDealOfflineNode, DealOfflineNode)

	} else {
		//CVNT收款
		c.AddFunc(e.CronSpecMin1, CvntRecharge)
		//CVNT转账
		c.AddFunc(e.CronSpecMin1, CvntTransfer)
		//USDT收款
		c.AddFunc(e.CronSpecMin1, UsdtRecharge)
		//USDT转账
		c.AddFunc(e.CronSpecMin1, UsdtTransfer)

		// 测试使用的定时任务
		//cronSpec := "01 47 16 * * ?"
		//c.AddFunc(cronSpec, StatisticalStage)
	}
	c.Start()
	return nil
}
